<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>大家都在看(攻略标签)</title>
    <#include "../common/header.ftl"/>

    <script type="text/javascript">
        $(function () {
            $('.inputBtn').click(function () {
                //
                $('#editForm input[name="strategyName"]').val($('#strategyId option:selected').html())
                var strategyId = $('#strategyId option:selected').val();
                if (strategyId == -1) {
                    $.messager.alert("温馨提示", "添加关联前请先选择攻略");
                    return;
                }

                $('#editModal').modal('show');
            });
            // 提交表单
            $('.btn_submit').click(function () {
                // 提交前将攻略id携带到服务器
                $('#editForm input[name="strategyId"]').val($('#strategyId').val());
                $('#editForm').ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.href = '/strategyTag/list.do';
                    } else {
                        $.messager.alert("温馨提示", data.msg);
                    }
                });

            });
        });
    </script>

</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "strategyTag" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>大家都在看(攻略标签)</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyTag/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label>攻略搜索</label>
                        <select name="strategyId" id="strategyId" class="form-control">
                            <option value="-1">请选择攻略</option>
                                <#list strategy as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                        </select>
                        <script>
                            $('#strategyId').val(${strategyId!});
                        </script>
                    </div>
                    <div class="form-group">
                        <button id="query" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 添加关联</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>关联标签</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list list as tag>
                    <tr>
                        <td>${tag.name!}</td>
                        <td>
                            <a href="/strategyTag/delete.do?tagId=${tag.id}&strategyId=${strategyId!}"
                               class="btn btn-danger">删除</a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyTag/save.do" method="post" id="editForm">
                    <input type="hidden" name="strategyId"/>
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="strategyName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">关联标签 ：</label>
                        <div class="col-sm-6">
                            <select name="tagId" id="tagId" class="form-control">
                                    <#list tag as t>
                                        <option value="${t.id!}">${t.name!}</option>
                                    </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>